import { Dialog, Notify } from 'quasar'

export default {
  error (message) {
    this.errors([message])
  },
  errors (errors) {
    errors.forEach(e => Notify.create({
      message: e,
      caption: 'Ошибка',
      color: 'red',
      position: 'top-right',
      actions: [{ icon: 'close', color: 'white' }]
    }))
  },
  messages (messages) {
    messages.forEach(m => Notify.create({
      caption: m,
      color: 'blue',
      position: 'top-right'
    }))
  },
  success (message, caption) {
    Notify.create({
      message: message || 'Успешно!',
      caption: caption || null,
      color: 'green',
      position: 'top-right',
      actions: [{ icon: 'close', color: 'white' }]
    })
  },
  defaultError: ['Неизвестная ошибка'],
  confirmAlert (message, callback, ok = null, html = false, onCancel = () => {}, cancel = null) {
    if (!ok) {
      ok = {
        color: 'red',
        label: 'Подтвердить'
      }
    }
    if (!cancel) {
      cancel = {
        label: 'Отмена'
      }
    }
    Dialog.create({
      title: 'Вы уверены?',
      message,
      ok,
      html,
      cancel
    }).onOk(callback).onCancel(onCancel)
  },

}
